# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer:
pkgname=ocaml-labltk
_pkgname=labltk
pkgver=8.06.5
_pkgkey=1764	# it changes with version update
pkgrel=1
_ocamlver=4.07.1
pkgdesc="Tcl/Tk interface for OCaml"
url="http://labltk.forge.ocamlcore.org/"
arch="aarch64 ppc64le x86_64"  # limited by ocaml aport
license="LGPL-2.0-or-later-WITH-linking-exception"
depends="ocaml-runtime"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="ocaml=~$_ocamlver ocaml-compiler-libs=~$_ocamlver tcl-dev tk tk-dev"
options="!check"  # no tests provided
subpackages="$pkgname-dev"
source="https://forge.ocamlcore.org/frs/download.php/$_pkgkey/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	cd "$builddir"

	./configure --tk-no-x11
	make -j1 all
	make -j1 opt
}

package() {
	local libdir="$pkgdir/usr/lib/ocaml"
	cd "$builddir"

	mkdir -p "$libdir"/$_pkgname \
		"$libdir"/stublibs \
		"$pkgdir"/usr/bin

	make install \
		BINDIR="$pkgdir/usr/bin" \
		INSTALLDIR="$pkgdir/usr/lib/ocaml/$_pkgname" \
		STUBLIBDIR="$pkgdir/usr/lib/ocaml/stublibs"

	# The *.o files are not installed by the Makefile.
	# AIUI that prevents linking with native code programs.
	install -m 0644 camltk/*.o "$libdir"/$_pkgname/
}

dev() {
	local sitelib="usr/lib/ocaml/$_pkgname"
	default_dev

	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/

	cd "$pkgdir"/$sitelib
	mkdir -p "$subpkgdir"/$sitelib
	mv *.cmx *.cmxa *.mli "$subpkgdir"/$sitelib/
}

sha512sums="8a6bfefd1ba8ef1fb54c284a06067007dd48833a475e24c787c0c2100a30a5ab018606ca3e79fd0fa323b6759de0ae3c7e6ef881e662bf1d7f84e920c7bebe7a  labltk-8.06.5.tar.gz"
